package cn.yuyiling.jelly.qa.controller;

import cn.yuyiling.jelly.qa.api.CommentService;
import cn.yuyiling.jelly.qa.mongodb.entity.Comment;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @DubboReference(scope = "remote")
    private CommentService commentService;

    @PutMapping("/question/{questionId}")
    public Comment createCommentWithQuestion(@PathVariable String questionId, @RequestBody Comment comment) {
        return commentService.createCommentWithQuestion(questionId, comment);
    }

    @PutMapping("/answer/{answerId}")
    public Comment createCommentWithAnswer(@PathVariable String answerId, @RequestBody Comment comment) {
        return commentService.createCommentWithAnswer(answerId, comment);
    }

    @PutMapping("/like/{id}")
    public Comment likeComment(@PathVariable String id) {
        return commentService.likeComment(id);
    }

    @PutMapping("/dislike/{id}")
    public Comment dislikeComment(@PathVariable String id) {
        return commentService.dislikeComment(id);
    }

    @DeleteMapping("/{id}")
    public void deleteComment(@PathVariable String id) {
        commentService.deleteCommentAndRelatedData(id);
    }
}
